package cn.wolfcode.education.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.util.Date;

@Getter@Setter@ToString
public class DayWork {
    /**
     * 任务处理状态
     */
    public static final int STATIC_ZERO = 0;//初始状态
    public static final int STATIC_PASS = 1;//已完成
    public static final int STATIC_ON = 2;//处理中
    public static final int STATIC_FAIL = 3;//失败
    private Long id;

    /**
     * 任务处理人
     */
    private Employee employee;
    /**
     * 所属部门
     */
    private Dept dept;
    /**
     * 任务描述
     */
    private String workDescription;
    /**
     * 处理描述
     */
    private String descriptionHandle;
    /**
     * 任务时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date workTime;

    private int state = STATIC_ZERO;
    public String getStateString(){
        if (state == 0){
            return "初始状态";
        }
        if (state == 1){
            return "已完成";
        }
        if (state == 2){
            return "处理中";
        }
            return "失败";
    }

    public String getWorkDescriptionString() {
        if (StringUtils.hasLength(workDescription)){
            if (workDescription.length() >30){
                String ret = workDescription.substring(0, 30);
                return ret;
            }
        }
        return workDescription;
    }

    public String getDescriptionHandleString() {
        if (StringUtils.hasLength(descriptionHandle)){
            if (descriptionHandle.length() >30){
                String rest = descriptionHandle.substring(0, 30);
                return rest;
            }
        }
        return descriptionHandle;
    }
}